package com.fengplus.demo.mapper;

import com.fengplus.demo.entity.AppOrder;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface AppOrderMapper {

    @Select("select * from app_order")
    List<AppOrder> findList();

    @Select("select * from app_order where id = #{id}")
    AppOrder findOne(Long id);

    @Insert("insert into app_order" +
        " (user_id, product_id, sn, amount, count, body, remark, status, created_at, updated_at)" +
        " values" +
        " (#{userId}, #{productId}, #{sn}, #{amount}, #{count}, #{body}, #{remark}, 0, now(), now())")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int save(AppOrder order);

    @Update("update app_order set status = #{status}, updated_at = now() where id = #{id}")
    int updateStatus(@Param("id") Long id, @Param("status") Integer status);

    @Delete("delete from app_order where id = #{id} and status = -1")
    int delete(Long id);

}
